<?php
/*
 * Session stuff
 */
ini_set('session.save_path',$_SERVER[DOCUMENT_ROOT].'/data/session');
ini_set('session.gc_maxlifetime',28800);
ini_set('session.gc_probability',1);
ini_set('session.gc_divisor',1);
session_start();

/*
 * REQUIRED & INCLUDE FILES
 */
require_once($_SERVER[DOCUMENT_ROOT]."/includes/config.inc.php");
require_once($_SERVER[DOCUMENT_ROOT]."/includes/functions.php");
require_once($_SERVER[DOCUMENT_ROOT]."/includes/classes/class.contact.php");
require_once($_SERVER[DOCUMENT_ROOT]."/includes/classes/class.events.php");
require_once($_SERVER[DOCUMENT_ROOT]."/includes/classes/class.getData.php");
require_once($_SERVER[DOCUMENT_ROOT]."/includes/classes/class.accountAccess.php");
require_once($_SERVER[DOCUMENT_ROOT]."/includes/classes/class.accountInfo.php");
require_once($_SERVER[DOCUMENT_ROOT]."/includes/classes/class.library.php");
require_once($_SERVER[DOCUMENT_ROOT]."/includes/classes/class.tags.php");
require_once($_SERVER[DOCUMENT_ROOT]."/includes/classes/class.emails.php");
require_once($_SERVER[DOCUMENT_ROOT]."/includes/classes/class.resources.php");
require_once($_SERVER[DOCUMENT_ROOT]."/includes/classes/class.resourceProviders.php");

// What page are we on?
$selfArray = explode("/", $_SERVER[PHP_SELF]);
$elements = count($selfArray);
$last_element = $elements - 1;
$thisPage = $selfArray[$last_element];

/*
 * Create query string to append to Text Only link and Language 
 * select box
 */
$urlQueryString = '';
foreach($_GET as $variable => $value) {
	if ($variable != 'to') {
		$urlQueryString .= $variable.'='.$value.'&';
	}	
}
/*
 * Remove traling &
 */
$urlQueryString = substr($urlQueryString,0,-1);

/*
 * Should we turn on the main menu bar and the white page bottom?
 */
if ($thisPage != 'index.php') {
	$mainMenu = 1;
	if ($rightCol == 1) {
		$pageBGCSSClass     = 'pageBackgroundColumns';
		$pageBottomCSSClass = 'pageBackgroundBottomRightCol';
	} else {
		$pageBottomCSSClass = 'pageBackgroundBottomWhite';
	}	
} else {
	$mainMenu = 0;
	$pageBGCSSClass     = 'pageBackground';
	$pageBottomCSSClass = 'pageBackgroundBottomBlue';
}

/*
 * Cookie expiration
 */
$cookieExpire = time()+COOKIE_EXPIRE;

/*
 * Check for default font size
 */
if (!isset($_SESSION[ts])) {
	$_SESSION[ts] = FONT_SIZE;
}

if (!empty($_GET[ts])) {
	$fontSize = $_GET[ts];
	
	if ($fontSize == 'larger') {
		$fontSize = $_SESSION[ts]+.1;
	} elseif ($fontSize == 'smaller') {
		$fontSize = $_SESSION[ts]-.1;
	}
	$_SESSION[ts] = $fontSize;
}

/*
 * Check translation language
 */
if (!empty($_POST['language'])) {
	$_SESSION['language'] = $_POST['language'];
	/*
	 * Set language cookie
	 */
	setcookie('language', $_POST['language'],$cookieExpire,'/','.ChildDisabilityConnection.org');
}
if (!isset($_SESSION['language'])) {
	/*
	 * Check language cookie
	 */
	if (isset($_COOKIE['language'])) {
		$defaultLanguage = $_COOKIE['language'];
		$_SESSION['language'] = $defaultLanguage;
	} else {
		$defaultLanguage = DEFAULT_LANGUAGE;
		/*
	 	* Set language cookie
	 	*/
		setcookie('language',$defaultLanguage,$cookieExpire,'/','.ChildDisabilityConnection.org');
	}
} else {
	$defaultLanguage = $_SESSION['language']; 
}

// Are we logging out?
if ($_GET[logout] == 1) {
	$_SESSION = array();
	if (isset($_COOKIE[session_name()])) {
	    setcookie(session_name(), '', time()-42000, '/');
	}	
	session_destroy();
}

// Zend Framework Includes
ini_set('include_path', '.:./:../:../../:../../../:/Zend:./Zend:../Zend:../../Zend:../../../Zend:'.$_SERVER[DOCUMENT_ROOT].'/Zend');
require_once $_SERVER[DOCUMENT_ROOT].'/Zend/Json.php';
require_once $_SERVER[DOCUMENT_ROOT].'/Zend/Db.php';
require_once $_SERVER[DOCUMENT_ROOT].'/Zend/Date.php';
require_once $_SERVER[DOCUMENT_ROOT].'/Zend/Mail.php';
require_once $_SERVER[DOCUMENT_ROOT].'/Zend/Validate/EmailAddress.php';
require_once $_SERVER[DOCUMENT_ROOT].'/Zend/Translate.php';
require_once $_SERVER[DOCUMENT_ROOT].'/Zend/Service/Amazon.php';

/*
 * We should include a site-wide translation file and a page specific translation file. 
 */
$translate = new Zend_Translate('tmx', $_SERVER[DOCUMENT_ROOT].'/languages/translations.tmx', $defaultLanguage);

// Set default timezone
date_default_timezone_set('America/Los_Angeles');

// Database Connection
// Do it the old fashioned way until we get the MySQL PDO driver installed.
$dbname = 'childdis';
$dbhost = 'cougar.wou.edu';
$dbuser = 'childdis';
$dbpass = 'no!dis';
$db = mysql_connect($dbhost,$dbuser,$dbpass);	
mysql_query ('SET NAMES UTF8');
?>